home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / sun / rlelib / rle_getcom.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-15  |  2.5 KB  |  97 lines

  1. /*
  2.  * This software is copyrighted as noted below.  It may be freely copied,
  3.  * modified, and redistributed, provided that the copyright notice is 
  4.  * preserved on all copies.
  5.  * 
  6.  * There is no warranty or other guarantee of fitness for this software,
  7.  * it is provided solely "as is".  Bug reports or fixes may be sent
  8.  * to the author, who may or may not act on them as he desires.
  9.  *
  10.  * You may not include this software in a program or other software product
  11.  * without supplying the source, or without informing the end-user that the 
  12.  * source is available for no extra charge.
  13.  *
  14.  * If you modify this software, you should include a notice giving the
  15.  * name of the person performing the modification, the date of modification,
  16.  * and the reason for such modification.
  17.  */
  18. /* 
  19.  * rle_getcom.c - Get specific comments from the_hdr structure.
  20.  * 
  21.  * Author:    Spencer W. Thomas
  22.  *         Computer Science Dept.
  23.  *         University of Utah
  24.  * Date:    Sun Jan 25 1987
  25.  * Copyright (c) 1987, University of Utah
  26.  */
  27.  
  28. #include <stdio.h>
  29. #include <rle.h>
  30.  
  31. /*****************************************************************
  32.  * TAG( match )
  33.  * 
  34.  * Match a name against a test string for "name=value" or "name".
  35.  * If it matches name=value, return pointer to value part, if just
  36.  * name, return pointer to NUL at end of string.  If no match, return NULL.
  37.  *
  38.  * Inputs:
  39.  *     n:    Name to match.  May also be "name=value" to make it easier
  40.  *        to replace comments.
  41.  *    v:    Test string.
  42.  * Outputs:
  43.  *     Returns pointer as above.
  44.  * Assumptions:
  45.  *    [None]
  46.  * Algorithm:
  47.  *    [None]
  48.  */
  49. static char *
  50. match( n, v )
  51. register char *n;
  52. register char *v;
  53. {
  54.     for ( ; *n != '\0' && *n != '=' && *n == *v; n++, v++ )
  55.     ;
  56.     if (*n == '\0' || *n == '=')
  57.     if ( *v == '\0' )
  58.         return v;
  59.     else if ( *v == '=' )
  60.         return ++v;
  61.  
  62.     return NULL;
  63. }
  64.  
  65. /*****************************************************************
  66.  * TAG( rle_getcom )
  67.  * 
  68.  * Return a pointer to the value part of a name=value pair in the comments.
  69.  * Inputs:
  70.  *     name:        Name part of the comment to search for.
  71.  *    the_hdr:    rle_dflt_hdr structure.
  72.  * Outputs:
  73.  *     Returns pointer to value part of comment or NULL if no match.
  74.  * Assumptions:
  75.  *    [None]
  76.  * Algorithm:
  77.  *    [None]
  78.  */
  79. char *
  80. rle_getcom( name, the_hdr )
  81. CONST_DECL char *name;
  82. rle_hdr *the_hdr;
  83. {
  84.     CONST_DECL char ** cp;
  85.     char * v;
  86.  
  87.     if ( the_hdr->comments == NULL )
  88.     return NULL;
  89.  
  90.     for ( cp = the_hdr->comments; *cp; cp++ )
  91.     if ( (v = match( name, *cp )) != NULL )
  92.         return v;
  93.  
  94.     return NULL;
  95. }
  96.  
  97.